package laba5;

import laba2.*;
import interfaces.task2.FractionNumber;

/**
 *
 * @author yakimovich
 */
public class FractionNumberImpl implements FractionNumber {

    private int dividend;
    private int divisor;

    /**
     * creates a FractionNumberImpl by default
     */
    public FractionNumberImpl() {
    }

    /**
     * creates a FractionNumberImpl by default
     * @param dividend
     * @param divisor  
     */
    public FractionNumberImpl(int dividend, int divisor) {
        this.dividend = dividend;
        if (divisor == 0) {
            throw new IllegalArgumentException();
        }
        this.divisor = divisor;
    }

    /**
     * @param i specified a dividend
     * @throws IllegalArgumentException  
     */
    @Override
    public void setDividend(int i) throws IllegalArgumentException {
        dividend = i;
    }

    /**
     * @return the dividend
     */
    @Override
    public int getDividend() {
        return dividend;
    }

    /**
     * @param i specified a divisor
     */
    @Override
    public void setDivisor(int i) {
        if (i == 0) {
            throw new IllegalArgumentException();
        }
        divisor = i;
    }

    /**
     * @return the divisor
     */
    @Override
    public int getDivisor() {
        return divisor;
    }

    /**
     *
     * @return value of the FractionNumberImpl
     */
    @Override
    public double value() {
        return (double) dividend / divisor;
    }

    /**
     *
     * @return the string representation for the value of the FractionNumberImpl
     */
    @Override
    public String toStringValue() {
        return dividend + " / " + divisor + " is " + value();
    }
}
